/*
 * LogInContentPane.java
 *
 * Created on December 15, 2007, 6:05 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.fie.contentpanes;

import com.fie.database.Connector;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

/**
 *
 * @author joseacuna-rohter
 */
public class LogInContentPane {
    
    private JPanel totalGUI;
    private JLabel titleLabel;
    private JTextField usernameField;
    private JPasswordField passwordField;
    private JButton loginButton;
    private StockTableContentPane stcp;
    private JFrame mainFrame;
    
    private JLabel usernameLabel;
    private JLabel passwordLabel;
    /** Creates a new instance of LogInContentPane */
    public LogInContentPane(JFrame mainFrame) {
        this.mainFrame = mainFrame; 
    }
    
    
    public Container createContentPane()
    {
        
       
        // We create a bottom JPanel to place everything on.
        totalGUI = new JPanel();
        
        // We set the Layout Manager to null so we can manually place
        // the Panels.
        totalGUI.setLayout(null);
        
        // Now we create a new panel, size it, shape it,color it red.
        // then add it to the bottom JPanel.
        JPanel fieldsPanel = new JPanel();
        fieldsPanel.setBackground(Color.white);
        fieldsPanel.setLocation(250, 40);
        fieldsPanel.setSize(150,150);
        
        JPanel titlePanel = new JPanel();
        titlePanel.setBackground(Color.white);
        titlePanel.setLocation(200,10);
        titlePanel.setSize(300,30);
        
        JPanel labelsPanel = new JPanel();
        labelsPanel.setBackground(Color.white);
        labelsPanel.setLocation(170,45);
        labelsPanel.setSize(90,40);
        
        usernameLabel = new JLabel("username: ");
        passwordLabel = new JLabel("password: ");
        usernameLabel.setFont(new Font("Arial Terminal",1,12));
        passwordLabel.setFont(new Font("Arial Terminal",1,12));
        
        labelsPanel.add(usernameLabel);
        labelsPanel.add(passwordLabel);
        
        usernameField = new JTextField(10);       
        passwordField = new JPasswordField(10);
        loginButton = new JButton("Login");
        loginButton.setBackground(Color.WHITE);
        
        titleLabel = new JLabel("Financial Information Secure Login");
        
        loginButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                actionLoginPerformed(evt);
               
            }
        });
        
        titleLabel.setFont(new Font("Arial Terminal",
                1,12));
        
        titlePanel.add(titleLabel);
        fieldsPanel.add(usernameField);
        fieldsPanel.add(passwordField);
        fieldsPanel.add(loginButton);
        
        
        
        
        
        totalGUI.add(titlePanel);
        totalGUI.add(fieldsPanel);
        totalGUI.add(labelsPanel);
        
        // Finally we return the JPanel.
        totalGUI.setOpaque(true);
        
        return totalGUI;
    }
    
    
    public void actionLoginPerformed(ActionEvent e) {
        System.out.println("Login Pressed");
        Connector c = Connector.myConnector;
        if(c.logIn(usernameField.getText(),passwordField.getPassword())){
            totalGUI.removeAll();
            stcp = new StockTableContentPane(
                    c.getCustomerID(usernameField.getText()));
            
            updateUI();
        }    
            
    }
    
    public void updateUI(){
        totalGUI.updateUI();
        mainFrame.setContentPane(stcp.createContentPane());
        mainFrame.setTitle("Watch List");
        
    }
    
}
